﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WarehouseWebAPP.code.BLL;

namespace WarehouseWebAPP.Pages.user.New_Entities
{
    public partial class NewComponent : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void ComponentDetailsView_DataBound(object sender, EventArgs e)
        {
            Label vendor = (Label)ComponentDetailsView.FindControl("VendorLabel");
                Label supplier = (Label)ComponentDetailsView.FindControl("SupplierLabel");

                if (vendor != null & supplier != null)
                {
                    VendorBLL vendorBLL = new VendorBLL();
                    SupplierBLL supplierBLL = new SupplierBLL();
                    try
                    {
                        vendor.Text = vendorBLL.VendorGetByNum(new Guid(vendor.Text))[0].vendor_name;
                        supplier.Text = supplierBLL.SupplierGetByNum(new Guid(supplier.Text))[0].supplier_name;
                    }
                    finally
                    {
                        //TODO
                        //we should add dispose here
                        // we need to add dispose function foreach bll
                        // or maybe the detailsview disposes alone ,
                        // need to check, because there exists disposing event
                    }
                }
        }

        protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
        {

            ComponentBLL componentBLL = new ComponentBLL();
            try
            {
                if (componentBLL.ComponentGetBySN(args.Value).Rows.Count > 0)
                    args.IsValid = false;
                else
                    args.IsValid = true;
            }
            finally
            {
                //TODO
                //we should add dispose here
                // we need to add dispose function foreach bll
                // or maybe the detailsview disposes alone ,
                // need to check, because there exists disposing event
            }

        }
    }
}
